<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: ui/checkbox.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: ui/checkbox.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>
/*-------------------------------------------------------
 * checkbox.js
 * date: 2012-10-08
 * author: Q
 * powered by wayixia.com
---------------------------------------------------------*/

/** 复选框
 * 
 * @constructor
 * @param {Object} json - 构造参数
 * @param {string|dom} json.id - 渲染的元素对象
 * @param {bool} json.checked - 初始状态
 * @param {Q.CheckBox.callback} - onchange事件回调
 */
Q.CheckBox = Q.extend({
  hwnd: null,
  __init__: function(json) {
    json = json || {}
    this.hwnd = Q.$(json.id);
    this.onchange = json.onchange || function(id) {}
    this.setCheck(!!json.checked);
    this.hwnd.onclick = (function(t) { return function() {  
      t.setCheck(!t.checked()); 
    }})(this);
  },

  /** 获取check状态
   * 
   * @memberof Q.CheckBox.prototype
   * @returns {bool} 是否选中
   */
  checked : function() {
    return Q.hasClass(this.hwnd, "checked");
  },

  /** 设置勾选状态， 触发onchange事件
   *
   * @memberof Q.CheckBox.prototype
   * @param {bool} checked - 是否勾选
   */
  setCheck : function(checked) {
    if(this.checked() == checked) 
      return;
    if(checked) {
      Q.addClass(this.hwnd, "checked");
    } else {
      Q.removeClass(this.hwnd, "checked");
    }
    this.onchange(checked);
  }
});
</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Q.Application.html">Application</a></li><li><a href="Q.CheckBox.html">CheckBox</a></li><li><a href="Q.Dialog.html">Dialog</a></li><li><a href="Q.DropDownList.html">DropDownList</a></li><li><a href="Q.HashMap.html">HashMap</a></li><li><a href="Q.List.html">List</a></li><li><a href="Q.List.Node.html">Node</a></li><li><a href="Q.Menu.html">Menu</a></li><li><a href="Q.MenuBar.html">MenuBar</a></li><li><a href="Q.MenuItem.html">MenuItem</a></li><li><a href="Q.Slider.html">Slider</a></li><li><a href="Q.Store.html">Store</a></li><li><a href="Q.Table.html">Table</a></li><li><a href="Q.UI.html">UI</a></li><li><a href="Q.UIApplication.html">UIApplication</a></li><li><a href="Q.Window.html">Window</a></li></ul><h3>Namespaces</h3><ul><li><a href="Q.html">Q</a></li></ul><h3>Global</h3><ul><li><a href="global.html#CONST">CONST</a></li><li><a href="global.html#end">end</a></li><li><a href="global.html#hwnd">hwnd</a></li><li><a href="global.html#item">item</a></li><li><a href="global.html#MENU_SEPERATOR">MENU_SEPERATOR</a></li><li><a href="global.html#MESSAGE">MESSAGE</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0</a> on Sun May 24 2015 11:21:15 GMT+0800 (中国标准时间)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
